package com.platform.rpc;

import com.platform.rpc.service.impl.HelloWorldImpl;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import javax.xml.ws.Endpoint;

/**
 * 测试HellWorld类
 * User: wangyanginfo
 * Date: 13-1-16
 * Time: 下午2:53
 *
 */
public class StartService {

	private static String address = "http://localhost:9000/helloWorld";

	public static void main(String args[]) throws Exception {
		servicePublicsh();
		System.out.println("Server ready...");
		Thread.sleep(5 * 60 * 1000);
		System.out.println("Server exiting");
		System.exit(0);
	}


	public static void endpointPublicsh() {
		// START SNIPPET: publish
		System.out.println("Starting Server");
		HelloWorldImpl implementor = new HelloWorldImpl();
		Endpoint.publish(address, implementor);
		// END SNIPPET: publish
	}

	public static void servicePublicsh() {
		//这里利用的就是JaxWsServerFactoryBean
		JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
		HelloWorldImpl service = new HelloWorldImpl();
		//服务类接口
		serverFactoryBean.setServiceClass(HelloWorldImpl.class);
		//设置地址
		serverFactoryBean.setAddress(address);
		serverFactoryBean.setServiceBean(service);
		serverFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
		serverFactoryBean.create();
	}

}
